<template>
  <!-- 对话框(添加 / 修改) -->
  <el-dialog
    title="学生考勤"
    :visible.sync="show"
    width="80%"
    append-to-body
    :before-close="cancel"
    :close-on-click-modal="false"
  >
    <div class="app-container">
      <!-- 搜索工作栏 -->
      <!-- 搜索工作栏 -->
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <!-- <el-form-item label="星期" prop="weekId">
          <el-input
            v-model="queryParams.weekId"
            placeholder="请输入星期"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item label="学院" prop="collegeId">
          <college-selector v-model="queryParams.collegeId" />
        </el-form-item>
        <el-form-item label="系部" prop="departmentsId">
          <departments-selector
            v-model="queryParams.departmentsId"
            :college-id="queryParams.collegeId"
          />
        </el-form-item>
        <el-form-item label="专业" prop="professionId">
          <professions-selector
            v-model="queryParams.professionId"
            :department-id="queryParams.departmentsId"
          />
        </el-form-item>
        <el-form-item label="班级" prop="classesId">
          <classes-from-selector
            v-model="queryParams.classesId"
            :profession-id="queryParams.professionId"
          />
        </el-form-item>
        <el-form-item label="打卡时间" prop="clockTime">
          <!-- <el-date-picker
            v-model="queryParams.clockTime"
            style="width: 240px"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          /> -->
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            v-model="queryParams.clockStartTime"
            placeholder="开始日期"
          ></el-date-picker
          ><span>-</span
          ><el-date-picker
            type="date"
            v-model="queryParams.clockEndTime"
            value-format="yyyy-MM-dd"
            placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="课程ID" prop="subjectId">
          <el-input
            v-model="queryParams.subjectId"
            placeholder="请输入课程ID"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <!-- <el-form-item label="教室信息" prop="roomId">
          <el-input
            v-model="queryParams.roomId"
            placeholder="请输入教室信息"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item label="打卡结果" prop="clockStatus">
          <el-select
            v-model="queryParams.clockStatus"
            placeholder="请选择打卡结果"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in this.getDictDatas(
                DICT_TYPE.ACCOMMODATION_CLOCK_STATUS
              )"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="教师信息" prop="teacherId">
                    <el-input v-model="queryParams.teacherId" placeholder="请输入教师信息" clearable @keyup.enter.native="handleQuery"/>
                  </el-form-item>-->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-col :span="1.5">
        <el-button type="primary" plain @click="showAudit = true"
          >请假审批</el-button
        >
      </el-col>
      <!-- 操作工具栏 -->
      <!-- <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            @click="audit(0, sourceId)"
            v-hasPermi="['collegebase:classroom-info:create']"
            >审核</el-button
          >
        </el-col>
      </el-row> -->

      <!-- 列表 -->
      <el-table v-loading="loading" :data="list">
        <!-- <el-table-column label="主键" align="center" prop="id" /> -->
        <!-- <el-table-column label="上课时间ID" align="center" prop="studyTimeId" /> -->
        <el-table-column label="学院" align="center" prop="collegeName" />
        <el-table-column label="系部" align="center" prop="departmentName" />
        <!-- <el-table-column label="星期" align="center" prop="weekId" /> -->
        <el-table-column label="班级" align="center" prop="className" />
        <!-- <el-table-column label="角色" align="center" prop="clockRole">
          <template slot-scope="scope">
            <dict-tag
              :type="DICT_TYPE.STUDY_CLOCK_ROLE"
              :value="scope.row.clockRole"
            />
          </template>
        </el-table-column> -->

        <el-table-column label="姓名" align="center" prop="clockUserName" />
        <!-- <el-table-column label="课程ID" align="center" prop="subjectId" /> -->
        <el-table-column label="基准打卡" align="center" prop="standardTime" />
        <!-- <el-table-column label="教室信息" align="center" prop="roomName" /> -->
        <el-table-column
          label="打卡时间"
          align="center"
          prop="clockTime"
          width="165"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.clockTime) }}</span>
          </template>
        </el-table-column>

        <!-- <el-table-column label="打卡类型" align="center" prop="clockType">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.CLASS_CLOCK_TYPE" :value="scope.row.clockType" />
        </template>
      </el-table-column> -->
        <el-table-column label="打卡结果" align="center" prop="clockStatus">
          <template slot-scope="scope">
            <dict-tag
              :type="DICT_TYPE.ACCOMMODATION_CLOCK_STATUS"
              :value="scope.row.clockStatus"
            />
          </template>
        </el-table-column>
        <!-- <el-table-column label="教师信息" align="center" prop="teacherId" /> -->
        <!-- <el-table-column label="打卡备注" align="center" prop="clockRemark" /> -->
        <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
        <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column> -->
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['study:clock-record:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['study:clock-record:delete']">删除</el-button> -->

            <!-- v-hasPermi="['study:clock-record:query']" -->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-search"
              @click="handleQueryDetails(scope.row)"
              >查看详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <!-- 添加修改组件 -->
      <form-edit :show.sync="open" :title="title" ref="editDialog"></form-edit>
      <audit :show.sync="showAudit" />
    </div>
  </el-dialog>
</template>

<script>
import {
  createClockRecord,
  updateClockRecord,
  deleteClockRecord,
  getClockRecord,
  getClockRecordPage,
  exportClockRecordExcel,
} from "@/api/teacherSide/clockRecord";
import CollegeSelector from "@/components/CollegeSelector";
import ProfessionsSelector from "@/components/ProfessionsSelector";
import ClassesFromSelector from "@/components/ClassesFromSelector";
import DepartmentsSelector from "@/components/DepartmentsSelector";
import formEdit from "./ClockformEdit.vue";
import audit from './audit.vue'
export default {
  name: "ClockRecord",
  components: {
    formEdit,
    audit,
    CollegeSelector,
    ProfessionsSelector,
    ClassesFromSelector,
    DepartmentsSelector
  },
  props: {
    // 是否显示弹出层
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      showAudit: false,
      tags: [
        { name: "标签一", type: "" },
        { name: "标签二", type: "" },
        { name: "标签三", type: "" },
        { name: "标签四", type: "" },
        { name: "标签五", type: "" },
      ],
      showFeatures: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 打卡记录列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        collegeId: null,
        departmentsId: null,
        professionId: null,
        classesId: null,
        clockTime: [],
        clockStatus: null,
        clockStartTime: null,
        clockEndTime: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    cancel() {
      this.$emit("update:show", false);
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      this.queryParams.teacherId = this.queryParams.classesId ? null : this.$store.getters.userId;
      getClockRecordPage(this.queryParams).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 表单重置 */
    reset() {
      this.form = {
        collegeId: undefined,
        departmentsId: undefined,
        professionId: undefined,
        classesId: undefined,
        clockTime: undefined,
        clockStatus: undefined,
      };
      this.resetForm("form");
    },
    handleQueryDetails(row) {
      // this.refundDetail = JSON.parse(JSON.stringify(defaultRefundDetail));
      const id = row.id;
      getClockRecord(id).then(response => {
        let form = response.data;
        this.open = true;
        this.title = "查看";
        this.$refs.editDialog.initData(form);
      });

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.clockStartTime = null;
      this.queryParams.clockEndTime = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加打卡记录";
      this.$refs.editDialog.initData({});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      getClockRecord(id).then((response) => {
        let form = response.data;
        this.open = true;
        this.title = "修改打卡记录";
        this.$refs.editDialog.initData(form);
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除打卡记录编号为"' + id + '"的数据项?')
        .then(function () {
          return deleteClockRecord(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal
        .confirm("是否确认导出所有打卡记录数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportClockRecordExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "打卡记录.xls");
          this.exportLoading = false;
        })
        .catch(() => { });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.group-name {
  padding: 10px;
  border-bottom: 1px solid #f5f5f5;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: bold;
}
.item {
  margin: 10px 0;
}
</style>
